package cli

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
)

var (
	mongoURI     string
	databaseName string
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
	Use:   "mongen",
	Short: "MongoDB数据生成工具",
	Long:  `MonGen是一个高性能的MongoDB测试数据生成工具`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func init() {
	// 全局标志
	rootCmd.PersistentFlags().StringVarP(&mongoURI, "mongo-uri", "u", "mongodb://localhost:27017", "MongoDB连接URI (支持认证: mongodb://username:password@host:port)")
	rootCmd.PersistentFlags().StringVarP(&databaseName, "database", "d", "test", "数据库名称")
}

// GetMongoURI returns the MongoDB URI
func GetMongoURI() string {
	return mongoURI
}

// GetDatabaseName returns the database name
func GetDatabaseName() string {
	return databaseName
}
